package direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import util.RabbitUtil;

import java.io.IOException;

public class Provider {

  public static void main(String[] args) throws IOException {

    String exchangeName = "logs_direct";

    //获取连接对象
    Connection connection = RabbitUtil.getConnection( );//获取连接通道对象
    Channel channel =connection.createChannel();
    //通过通道声明交换机参数1:交换机名称参数2:direct路由模式
    channel.exchangeDeclare( exchangeName , "direct");//发送消息
    String routingkey ="error";
    channel.basicPublish(exchangeName ,routingkey,null, ("这是direct模型发布的基于routekey" + routingkey + "发送的消息").getBytes());

    RabbitUtil.closeConnectionAndChannel(channel,connection);
  }
}
